package com.ruoyi.cscec.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.cscec.domain.DataMonitor;
import com.ruoyi.cscec.service.IDataMonitorService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 数据监测Controller
 *
 * @author ruoyi
 * @date 2021-09-27
 */
@RestController
@RequestMapping("/monitor")
public class DataMonitorController extends BaseController
{
    @Autowired
    private IDataMonitorService dataMonitorService;

    /**
     * 查询数据监测列表
     */
    @PreAuthorize(hasPermi = "cscec:monitor:list")
    @GetMapping("/list")
    public TableDataInfo list(DataMonitor dataMonitor)
    {
        startPage();
        List<DataMonitor> list = dataMonitorService.selectDataMonitorList(dataMonitor);
        return getDataTable(list);
    }

    /**
     * 导出数据监测列表
     */
    @PreAuthorize(hasPermi = "cscec:monitor:export")
    @Log(title = "数据监测", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DataMonitor dataMonitor) throws IOException
    {
        List<DataMonitor> list = dataMonitorService.selectDataMonitorList(dataMonitor);
        ExcelUtil<DataMonitor> util = new ExcelUtil<DataMonitor>(DataMonitor.class);
        util.exportExcel(response, list, "数据监测数据");
    }

    /**
     * 获取数据监测详细信息
     */
    @PreAuthorize(hasPermi = "cscec:monitor:query")
    @GetMapping(value = "/{dmId}")
    public AjaxResult getInfo(@PathVariable("dmId") Long dmId)
    {
        return AjaxResult.success(dataMonitorService.selectDataMonitorByDmId(dmId));
    }

    /**
     * 新增数据监测
     */
    @PreAuthorize(hasPermi = "cscec:monitor:add")
    @Log(title = "数据监测", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DataMonitor dataMonitor)
    {
        return toAjax(dataMonitorService.insertDataMonitor(dataMonitor));
    }

    /**
     * 修改数据监测
     */
    @PreAuthorize(hasPermi = "cscec:monitor:edit")
    @Log(title = "数据监测", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DataMonitor dataMonitor)
    {
        return toAjax(dataMonitorService.updateDataMonitor(dataMonitor));
    }

    /**
     * 删除数据监测
     */
    @PreAuthorize(hasPermi = "cscec:monitor:remove")
    @Log(title = "数据监测", businessType = BusinessType.DELETE)
    @DeleteMapping("/{dmIds}")
    public AjaxResult remove(@PathVariable Long[] dmIds)
    {
        return toAjax(dataMonitorService.deleteDataMonitorByDmIds(dmIds));
    }
}
